package evostar.controller;

import evostar.result.Result;
import evostar.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping(value = "/login")
public class LoginController {
    @Autowired
    private UserService userService;

    @RequestMapping(value = "/")
    public String login() {
        return "login";
    }

    @RequestMapping(value = "/verify")
    @ResponseBody
    public Result<String> verify(HttpServletResponse response, String username, String password) {
        String token = userService.login(response, username, password);
        return Result.success(token);
    }
}
